home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
-
-
- #include "scout_locks.h"
-
- extern struct ExecBase *SysBase;
- extern struct DosLibrary *DOSBase;
-
- #define LockPuddleSize 1024
- #define LockThreshSize 512
-
- APTR LockPool = NULL;
-
- int lockanzahl, hiddenanzahl;
-
- __asm LONG locklist_dspfunc(register __a2 char **array, register __a1 struct LockEntry *lockentry, register __a0 struct Hook *hook) {
- if (lockentry) {
- *array++ = lockentry->lock_address;
- *array++ = lockentry->lock_access;
- *array++ = lockentry->lock_path;
- *array = NULL;
- } else {
- *array++ = ESC "bAddress";
- *array++ = ESC "bAccess";
- *array++ = ESC "bPath";
- *array++ = NULL;
- }
- return(0);
- }
-
- struct Hook locklist_dsphook = {
- {NULL, NULL},
- (ULONG (* )())locklist_dspfunc,
- NULL, NULL
- };
-
- void FreeLocks (void) {
- if (LockPool) {
- if (AP_Scout) {
- set (locktext,MUIA_Text_Contents,"");
- set (locktext2,MUIA_Text_Contents,"");
- DoMethod (locklist,MUIM_List_Clear);
- }
- AsmDeletePool (LockPool,SysBase);
- LockPool = NULL;
- }
- }
-
- APTR GetLocks (int sl_job, char *pattern, struct LockEntry **first) {
- struct LockEntry *lockentry,*previous = NULL;
- struct DosList *dev;
- unsigned long lock = 0, next, prev, lock2remove = 0;
- struct FileLock *lockptr;
- struct FileInfoBlock *infoBlock;
- APTR LocalPool = NULL;
-
- unsigned char *dest;
- unsigned char access[6];
-
- int erster, pattern_correct, i = LOCKSUPDATERATE;
-
- if (first)
- *first = 0;
-
- lockanzahl = 0;
- hiddenanzahl = 0;
- NoReqOn();
-
- LocalPool = AsmCreatePool (MEMF_ANY|MEMF_CLEAR,LockPuddleSize,LockThreshSize,SysBase);
-
- if (dest = AllocMem (PATHLENGTH*2+3, MEMF_CLEAR|MEMF_ANY)) {
- pattern_correct = ((((!pattern) || (*pattern == '\0')) && \
- (ParsePatternNoCase ("#?", dest, PATHLENGTH*2+2) != -1)) || \
- (ParsePatternNoCase (pattern, dest, PATHLENGTH*2+2) != -1));
-
- if (clientstate) {
- char tmpbuffer[256];
-
- if (SendDaemon ("GetLockList")) {
- while ((lockentry = AsmAllocPooled (LocalPool,sizeof (struct LockEntry),SysBase)) \
- && (ReceiveDecodedEntry ((UBYTE *) lockentry, sizeof (struct LockEntry) - 4)) \
- && (sgets (client_socket, tmpbuffer, 256))) {
-
- IsHex (lockentry->lock_address, (long *) &lockentry->lock_ptr);
-
- if (MatchPatternNoCase (dest, tmpbuffer)) {
- if (lockentry->lock_path = AsmAllocPooled (LocalPool, strlen (tmpbuffer) + 1, SysBase)) {
- strncpy (lockentry->lock_path, tmpbuffer, strlen (tmpbuffer) + 1);
- }
- lockanzahl ++;
-
- if (! *first)
- *first = lockentry;
- if (previous)
- previous->lock_next = lockentry;
-
- previous = lockentry;
- } else {
- hiddenanzahl++;
- }
- if (WI_Locks && !--i) {
- sprintf (tmpstr, "%d shown, %d hidden...", lockanzahl, hiddenanzahl);
- i = LOCKSUPDATERATE;
- DoMethod (AP_Scout,MUIM_Application_InputBuffered);
- set (locktext2,MUIA_Text_Contents,tmpstr);
- }
- }
- }
- } else {
- if ((pattern_correct) && (infoBlock = AllocMem (sizeof (struct FileInfoBlock), MEMF_CLEAR|MEMF_ANY))) {
- dev = DOSLIST;
- while (dev != 0) {
- if (dev->dol_Type == DLT_VOLUME){
- strncpy (tmpstr, (unsigned char *) ((dev->dol_Name)<<2)+1, FILENAMELENGTH);
- strcat (tmpstr, ":");
-
- if (lock = Lock (tmpstr, ACCESS_READ)) {
- erster = TRUE; next = 0;
-
- while ((next && (next != lock)) || (erster)) {
- if (erster)
- next = lock;
- lockptr = (struct FileLock *) (next<<2);
- if (!TypeOfMem (lockptr))
- break;
- if (lockptr->fl_Volume != ((ULONG) dev)>>2)
- break;
- if (Examine (next, infoBlock)) {
- if (sl_job == SL_LIST) {
- if (erster) {
- strcpy(access, "OWN");
- } else if (lockptr->fl_Access == ACCESS_READ) {
- strcpy(access, "READ");
- } else if (lockptr->fl_Access == ACCESS_WRITE) {
- strcpy(access, "WRITE");
- } else {
- strcpy(access, "----");
- }
- }
- NameFromLock (next, tmpstr, PATHLENGTH);
-
- if (MatchPatternNoCase (dest, tmpstr)) {
- if ((sl_job == SL_LIST) && (lockentry = AsmAllocPooled (LocalPool,sizeof (struct LockEntry),SysBase))) {
- if (! *first)
- *first = lockentry;
- if (previous)
- previous->lock_next = lockentry;
-
- lockentry->lock_ptr = (char *) lockptr;
- sprintf (lockentry->lock_address, "$%08x", lockptr);
- strcpy (lockentry->lock_access, access);
-
- if (lockentry->lock_path = AsmAllocPooled (LocalPool, strlen (tmpstr) + 1,SysBase)) {
- strcpy (lockentry->lock_path, tmpstr);
- }
-
- lockanzahl ++;
- previous = lockentry;
- } else if (sl_job == SL_REMOVE) {
- lockanzahl ++;
- lock2remove = next;
- } else if (sl_job == SL_COUNT) {
- lockanzahl ++;
- } else {
- hiddenanzahl++;
- }
- } else {
- hiddenanzahl++;
- }
- if ((WI_Locks) && (sl_job == SL_LIST) && (!(--i))) {
- sprintf (tmpstr, "%d shown, %d hidden...", lockanzahl, hiddenanzahl);
- i = LOCKSUPDATERATE;
- DoMethod (AP_Scout,MUIM_Application_InputBuffered);
- set (locktext2,MUIA_Text_Contents,tmpstr);
- }
- }
- erster = FALSE;
- prev = next;
- next = lockptr->fl_Link;
- if ((sl_job == SL_REMOVE) && (lock2remove)) {
- UnLock (lock2remove);
- lock2remove = NULL;
- }
- }
- UnLock (lock);
- lock = 0;
- }
- }
- dev = (struct DosList *) ((dev->dol_Next)<<2);
- }
- FreeMem (infoBlock, sizeof (struct FileInfoBlock));
- }
- NoReqOff();
- }
- FreeMem (dest, PATHLENGTH*2+3);
- }
- return (LocalPool);
- }
-
- void PrintLocks (char *filename) {
- int i=1;
- BPTR handle;
- APTR lockpool = NULL;
- struct LockEntry *entryp;
-
- handle = HandlePrintStart (filename);
- if ((handle) && (PrintOneLine (handle, "\n Address Access Path\n\n"))) {
- if (! WI_Locks) {
- lockpool = GetLocks (SL_LIST, "#?", &entryp);
- }
- if (i) {
- for (i=0;;i++) {
- if (WI_Locks)
- DoMethod (locklist,MUIM_List_GetEntry,i,&entryp);
- if (!entryp) break;
-
- sprintf (tmpstr2, " %ls %-5ls %ls\n", entryp->lock_address, entryp->lock_access, entryp->lock_path);
- if (! (PrintOneLine (handle, tmpstr2)))
- break;
-
- if (! WI_Locks)
- entryp = entryp->lock_next;
- }
- }
- }
- if (lockpool)
- AsmDeletePool (lockpool,SysBase);
- HandlePrintStop();
- }
-
- void ShowLocks (void) {
- unsigned char *pattern;
- struct LockEntry *lock;
-
- ApplicationSleep();
- set (locklist,MUIA_List_Quiet,TRUE);
- set (locklist,MUIA_List_CompareHook,locklist_cmphook_ptr);
- set (BT_LockRemove, MUIA_Disabled, TRUE);
-
- FreeLocks();
-
- get (lockpattern, MUIA_String_Contents, &pattern);
- LockPool = GetLocks (SL_LIST, pattern, &lock);
-
- while (lock) {
- InsertSortedEntry (locklist, (APTR *) &lock);
- lock = lock->lock_next;
- }
-
- AwakeApplication();
- set (locklist, MUIA_List_Quiet, FALSE);
- MySetContents (locktext2, "%d shown, %d hidden. Done.", lockanzahl, hiddenanzahl);
- set (WI_Locks,MUIA_Window_ActiveObject,locklist);
- }
-
- void SendLockList (void) {
- unsigned char *pattern;
- struct LockEntry *lock;
-
- FreeLocks();
-
- get (lockpattern, MUIA_String_Contents, &pattern);
- LockPool = GetLocks (SL_LIST, pattern, &lock);
-
- while (lock) {
- SendEncodedEntry ((UBYTE *) lock, sizeof (struct LockEntry) - 4);
- if (lock->lock_path && lock->lock_path[0])
- SendClient ((UBYTE *) lock->lock_path);
- else
- SendClient (" ");
- lock = lock->lock_next;
- }
- FreeLocks();
- }
-
-